public class PatchString {

	public static void main(String[] args) throws Exception {
		String a = PatchString.patchString("1", 5, 1);
		System.out.println(a);

	}
	 public static final int PATCH_BEFORE = 1;//前补
	    public static final int PATCH_AFTER = 2;//后补
	    //补足
	    public static final String patchString(Object or,int len,int patchType) throws Exception{
	    	if(or == null){
	    		throw new Exception("patchString(Object or,int len,char patchChar,int patchType)方法or参数为空!");
	    	}
	    	String orStr = or.toString();
	    	String patchChar = null;
	    	if(isNum(orStr)){
	    		patchChar = "0";
	    	}else{
	    		patchChar = " ";
	    	}
	    	int strLen = orStr.length();
	    	if(strLen>len){
	    		throw new Exception(orStr+"长度大于补允长度大于"+len);
	    	}
	    	String paStr = "";
	    	for(int i=0;i<(len-strLen);i++){
	    		paStr = paStr+patchChar;
	    	}
	    	if(patchType == PATCH_BEFORE){
	    		return paStr+orStr;
	    	}else if(patchType == PATCH_AFTER){
	    		return orStr+paStr;
	    	}else{
	    		throw new Exception("patchString(Object or,int len,char patchChar,int patchType)不支持类型:"+patchType);
	    	}
	    }
	    
	    public static boolean isNum(String str){
	    	return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
	    }
}
